﻿using NFine.Domain.Entity.BusinessManage;
using NFine.Domain.IRepository.BusinessManage;
using NFine.Repository.BusinessManage;
using NFine.Code;
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;
using NFine.Domain.Entity.SystemManage;
using NFine.Data;
using NFine.Domain.ViewModel.QueryDto;

namespace NFine.Application.BusinessManage
{
    public class D_MemberChargeApp
    {
        private readonly ID_MemberCharge service = new D_MemberChargeRepository();


        public List<D_MemberCharge> GetList(Pagination pagination, string keyword)
        {
            var expression = ExtLinq.True<D_MemberCharge>();
            if (!string.IsNullOrEmpty(keyword))
            {
                expression = expression.And(t => t.F_Action.Contains(keyword));
                expression = expression.Or(t => t.F_UserName.Contains(keyword));
                expression = expression.Or(t => t.F_MemberName.Contains(keyword));
                expression = expression.Or(t => t.F_Remark.Contains(keyword));
            }
            return service.FindList(expression, pagination);
        }

        public List<D_MemberCharge> GetList()
        {
            return service.IQueryable().ToList();
        }

        public List<D_MemberCharge> GetGrid(string keyword)
        {
            var loginId = OperatorProvider.Provider.GetCurrent().UserId;
            var expression = ExtLinq.True<D_MemberCharge>();
            if (!string.IsNullOrEmpty(keyword))
            {
                expression = expression.And(t => t.F_Action.Contains(keyword) );
                expression = expression.Or(t => t.F_MemberName.Contains(keyword));
                expression = expression.Or(t => t.F_Remark.Contains(keyword));
            }
            expression = expression.And(t => t.F_UserId == loginId);
            return service.FindList(expression);
        }

        public D_MemberCharge GetForm(string keyValue)
        {
            return service.FindEntity(keyValue);
        }
        public void DeleteForm(string keyValue)
        {
            service.Delete(t => t.F_Id == keyValue);
        }
        public void SubmitForm(D_MemberCharge goodEntity, string keyValue)
        {
            if (!string.IsNullOrEmpty(keyValue))
            {
                goodEntity.Modify(keyValue);
                service.Update(goodEntity);
            }
            else
            {
                goodEntity.Create();
                service.Insert(goodEntity);
            }
        }

        public List<D_SalaryHistoryEntity> GetAllSaleGrid(Pagination pagination, SearchInputDto searchInput)
        {
            return null;


            /*
            var expression = ExtLinq.True<D_SalaryHistoryEntity>();
            var expression1 = ExtLinq.True<UserEntity>();
            var model = new D_SalaryHistoryEntity();
            if (!string.IsNullOrWhiteSpace(keyValue))
            {
                model = JsonConvert.DeserializeObject<D_SalaryHistoryEntity>(keyValue);
            }
            if (!string.IsNullOrEmpty(model.Account))
            {
                expression1 = expression1.And(t => t.F_Account.Contains(model.Account));
            }
            if (!string.IsNullOrEmpty(model.AccountName))
            {
                expression1 = expression1.And(t => t.F_RealName.Contains(model.AccountName));
            }
            if (!string.IsNullOrEmpty(model.ChangeType))
            {
                expression = expression.And(t => t.ChangeType.Contains(model.ChangeType));
            }
            return service.GetAllSaleGrid(expression, expression1, pagination);
            */
        }

        public List<D_SalaryHistoryEntity> GetAllsSaleGrid(Pagination pagination, string keyValue)
        {
            var expression = ExtLinq.True<D_SalaryHistoryEntity>();
            var expression1 = ExtLinq.True<UserEntity>();
            var model = new D_SalaryHistoryEntity();
            if (!string.IsNullOrWhiteSpace(keyValue))
            {
                model = JsonConvert.DeserializeObject<D_SalaryHistoryEntity>(keyValue);
            }
            if (!string.IsNullOrEmpty(model.Account))
            {
                expression1 = expression1.And(t => t.F_Account.Contains(model.Account));
            }
            if (!string.IsNullOrEmpty(model.AccountName))
            {
                expression1 = expression1.And(t => t.F_RealName.Contains(model.AccountName));
            }
            if (!string.IsNullOrEmpty(model.ChangeType))
            {
                expression = expression.And(t => t.ChangeType.Contains(model.ChangeType));
            }
            return service.GetAllSaleGrid(expression,expression1, pagination);
        }
    }
}
